import { getConstructorName } from "../../platform/utils/TypeUtil";


export class EzGameWebsocket{
    url:string
    webSocket:WebSocket
    onOpen: ((this: WebSocket, ev: Event) => any) | null;
    public static builder(){
        return new EzGameWebsocketBuilder();
    }
    start(){
        this.webSocket = new WebSocket(this.url)
        this.webSocket.binaryType = "arraybuffer";
        this.webSocket.onopen = this.onOpen
    }
    //TODO 防抖？

    //同步请求,阻塞，直到返回或超时

    //返回option
    sendMsgAync(msg:any){

    }
    //回调形式
    sendMsgBycb(msg:any,onResp:Function){
    }
}

export class EzGameWebsocketBuilder{
    esWs:EzGameWebsocket = null;

    constructor(){
        this.esWs = new EzGameWebsocket()
    }

    public url(url:string){
        this.esWs.url = url;
        return this
    }
    
    public onOpen(func:((this: WebSocket, ev: Event) => any) | null){
        this.esWs.onOpen = func;
        return this
    }

    public build(){
        return this.esWs
    }
}